package com.loyal.loyalerp.basedata.department.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import com.loyal.loyalerp.basedata.department.model.Department;
import com.loyal.loyalerp.basedata.department.model.DepartmentExample;
import com.loyal.loyalerp.model.GyPerson;

@Mapper
public interface DepartmentMapper {
	
	//根据id查name
	@Select("select deptname from gy_department where id=#{id}")
	String selectDeptnameByPrimaryKey(Integer id);
	
	@Select("select * from gy_department where deptName=#{deptname}")
	Department selectByDeptname(String deptname);

	List<Department> getChildsById(Integer id);

	List<GyPerson> getPersonsById(Integer id);

	List<GyPerson> getPersonsByIds(List<Integer> ids);

	List<GyPerson> getPersonsByDepartments(List<Department> departments);

	long countByExample(DepartmentExample example);

	@Delete("delete from gy_department where companyId=#{id}")
	int deleteByCompanyId(Integer id);

	int deleteByExample(DepartmentExample example);

	int deleteByPrimaryKey(Integer id);

	int insert(Department record);

	int insertSelective(Department record);
	
	List<Department> selectByExample(DepartmentExample example);
	/**
	 * spring cache默认的aop方式只支持public类型的方法，可用aspectj aop来解决<br>
	 * spring cache对接口中的方法的注解的key值使用的参数名取的是代理类或实现类的参数名
	 * @param id	这里的参数名是id，但是代理类的参数名却是arg0
	 * @return
	 */
//	@Cacheable(value="idSerializerCache",key="'select_'+#arg0")
	Department selectByPrimaryKey(Integer id);
	
	int updateByExampleSelective(@Param("record") Department record, @Param("example") DepartmentExample example);

	int updateByExample(@Param("record") Department record, @Param("example") DepartmentExample example);

	int updateByPrimaryKeySelective(Department record);

	int updateByPrimaryKey(Department record);
    @Select("select * from gy_department where companyId=#{id}")
	List<Department> selectByCompanyId(Integer id);
}